package socketinterface.server;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

public class RequestSocket {
	private Socket                 clientSocket = null;
	
	public synchronized Socket getClientSocket() {
		while (clientSocket == null) {
			try {
				wait();
			} catch (InterruptedException e) {
				
			}
		}
		return clientSocket;
	}
	
	public synchronized void openClientSocket(ServerSocket serverSocket) {
		try {
			clientSocket = serverSocket.accept();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		notifyAll();
	}
	
	public synchronized void closeClientSocket() {
		if(!clientSocket.isClosed()) {
			try {
				clientSocket.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
	
	public boolean isClosed(){
		return clientSocket.isClosed();
	}
}
